package rpc_1.object;

import com.sun.tools.internal.ws.processor.model.Response;
import lombok.Data;

import java.io.Serializable;

@Data
public class RpcResponse<T> implements Serializable {
    /*
    status of response
     */
    private Integer statusCode;
    /*
    extra message
     */
    private String message;
    /*
    data
     */
    private T data;

    /*
    message when success
     */
    public static <T> RpcResponse<T> success(T data,ResponseCode code){
        RpcResponse<T> response=new RpcResponse<T>();
        response.setStatusCode(code.getSUCCESS_CODE());
        response.setData(data);
        response.setMessage("success!cheers!!!");
        return response;
    }

    /*
    message when fail
     */
    public static <T> RpcResponse<T> fail(ResponseCode code){
        RpcResponse<T> response=new RpcResponse<T>();
        response.setStatusCode(code.getFAIL_CODE());
        response.setMessage(code.getMessage());
        return response;
    }

    public RpcResponse(){

    }
}
